package TreadPool;

import java.util.ArrayList;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

class MyThreadPoolExecutor3{
    private ArrayList<Thread>threadArrayList=new ArrayList<>();
    private BlockingQueue<Runnable>queue=new ArrayBlockingQueue<>(1000);
    public MyThreadPoolExecutor3(int n){
        for(int i=0;i<n;i++){
            Thread t=new Thread(()->{
                while (true) {


                    try {
                        Runnable runnable = queue.take();
                        runnable.run();

                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
            t.start();
            threadArrayList.add(t);

        }
    }
    public void submit(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }
}

public class Main3 {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPoolExecutor3 myThreadPoolExecutor3=new MyThreadPoolExecutor3(12);
        for(int i=0;i<1000;i++){
            int n=i;
            myThreadPoolExecutor3.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("执行任务"+n+"线程是"+Thread.currentThread().getName());
                }
            });

        }
    }
}
